

def getTaxRatio(taxSalary):

	ratiolist	=(
			(500,    0.05, 0),
			(2000,   0.10, 25),
			(5000,   0.15, 125),
			(20000,  0.20, 375),
			(40000,  0.25, 1375),
			(60000,  0.30, 3375),
			(80000,  0.35, 6375),
			(100000, 0.40, 10375),
			(9999999,0.45, 15375)
			)

	if taxSalary>= 0:		
		for ratio in ratiolist:
			if taxSalary<= ratio[0]:
				return (ratio[1], ratio[2])
	return (0, 0)

def calcYearAwardTax(yearAward):

	monthAward			= yearAward / 12
	taxRatio, taxAdjust	= getTaxRatio(monthAward)

	tax					= yearAward * taxRatio - taxAdjust
	resultAward			= yearAward - tax
	
	retcode				= (yearAward, resultAward, tax, taxRatio, taxAdjust)
	#print('yearAward= %d, resultAward= %f, tax= %f, taxRatio= %f, taxAdjust= %d'%retcode)
	return retcode


################################################################################

import sys
import os

argNum	= len(sys.argv)
if argNum == 1:
	scriptName	= os.path.basename(__file__)
	print('usage1:	%s awardUpperBound'%scriptName)
	print('usage2:	%s awardLowerBound awardUpperBound'%scriptName)
	sys.exit()


print('-----------------------------------------------------------------------')

awardLowerBound, awardUpperBound		= 0, 0
if argNum   == 2:
	awardUpperBound						= int(sys.argv[1])
elif argNum == 3:
	awardLowerBound, awardUpperBound	= int(sys.argv[1]), int(sys.argv[2])

if awardLowerBound> awardUpperBound:
		swap(awardLowerBound, awardUpperBound)
	
perfectAward, perfectGain				= 0, 0

for award in range(awardLowerBound, awardUpperBound + 1):
	retcode		= calcYearAwardTax(award)	
	if len(retcode) > 2:
		if retcode[1]> perfectGain:
			perfectAward	= retcode[0]
			perfectGain		= retcode[1]
		
		if award== awardUpperBound:
			print('upperBoundAward= %d,\tgain= %f,\ttax= %f'%(retcode[0], retcode[1], retcode[0] - retcode[1]))	

print("perfectAward= %d,\tgain= %f,\ttax= %f"%(perfectAward, perfectGain, perfectAward - perfectGain))



